package com.lu.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lu.model.entity.SysBrand;
import com.lu.model.request.BrandQueryRequest;
import com.lu.model.response.Result;
import com.lu.service.SysBrandService;
import lombok.RequiredArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 品牌 前端控制器
 * </p>
 *
 * @author zhanglu
 * @since 2022-07-31
 */
@RestController
@RequestMapping("/sys-brand")
@RequiredArgsConstructor
public class SysBrandController {

  private final SysBrandService brandService;

  @PreAuthorize("hasAuthority('/sys-brand/page-list')")
  @PostMapping("/page-list")
  public Result<Page<SysBrand>> pageList(@RequestBody BrandQueryRequest request){
    return Result.success(brandService.pageList(request));
  }

  @PostMapping("/list")
  public Result<List<SysBrand>> list(@RequestBody BrandQueryRequest request){
    return Result.success(brandService.brandList(request));
  }

  @PreAuthorize("hasAuthority('/sys-brand/get')")
  @GetMapping("/get/{id}")
  public Result<SysBrand> get(@PathVariable Long id){
    return Result.success(brandService.getById(id));
  }

  @PreAuthorize("hasAuthority('/sys-brand/add')")
  @PostMapping("/add")
  public Result<Long> add(@RequestBody SysBrand brand){
    return Result.success(brandService.addBrand(brand));
  }

  @PreAuthorize("hasAuthority('/sys-brand/update')")
  @PostMapping("/update")
  public Result<SysBrand> update(@RequestBody SysBrand brand){
    return Result.success(brandService.updateBrand(brand));
  }

  @PreAuthorize("hasAuthority('/sys-brand/delete')")
  @PostMapping("/delete/{id}")
  public Result delete(@PathVariable Long id){
    return Result.success(brandService.removeById(id));
  }

}
